@echo off
if %1*==* goto args
if %2*==* goto args

cls
set ts=%tmp%\~ts

echo == Cleaning after previous run
if exist %ts%\NUL rmdir /S /Q %ts%
if exist %2\NUL   rmdir /S /Q %2
if exist z_.Bat   del z_.Bat
if exist z_.dat   del z_.dat
if exist z_.log   del z_.log

echo == Creating repo @ %2
svnadmin create %2
if not %ERRORLEVEL%==0 goto err
z_.vbs ! %2
for /f "delims=" %%a in (z_.dat) do set new_repo=%%a
echo exit 0 >%2\hooks\pre-revprop-change.bat

echo == Creating temp @ %ts%
md %ts%
if not %ERRORLEVEL%==0 goto err

echo == Getting last rev number
for /F "usebackq skip=4 tokens=2" %%i in (`svn info -r HEAD %1`) do SET r=%%i && goto rev
goto err

:rev
echo == Processing revs 1 to %r%
for /L %%i in (1,1,%r%) do (
title Processing revs... %%i/%r%
echo === r%%i: processing changes
for /F "usebackq skip=3 tokens=1*" %%j in (`svn log -r %%i --verbose -q --incremental "%1"`) do (
z_.vbs %ERRORLEVEL% "%1" "%%k" %ts% %%i %%j "%new_repo%"
call z_.Bat
)
echo === r%%i: committing changes
svn propget svn:log --revprop -r %%i %1>z_.dat
if 1==%%i (
svn import %ts% %new_repo% -F z_.dat>NUL
if not %ERRORLEVEL%==0 goto err
svn checkout %new_repo% %ts% --force>NUL
if not %ERRORLEVEL%==0 goto err
) else (
svn commit %ts% -F z_.dat>NUL
if not %ERRORLEVEL%==0 goto err
svn update %ts%>NUL
)
svn propget svn:author --revprop -r %%i %1>z_.dat
if not %ERRORLEVEL%==0 goto err
for /f "delims=" %%a in (z_.dat) do svn propset svn:author "%%a" --revprop -r HEAD %new_repo% --force>NUL
if not %ERRORLEVEL%==0 goto err
svn propget svn:date --revprop -r %%i %1>z_.dat
if not %ERRORLEVEL%==0 goto err
svn propset svn:date --revprop -r HEAD %new_repo% -F z_.dat --force>NUL
if not %ERRORLEVEL%==0 goto err
)
title Finishing...
if not %ERRORLEVEL%==0 goto err

echo == Cleaning temp files
pause
if exist %ts%\NUL rmdir /S /Q %ts%
if exist z_.Bat   del z_.Bat
if exist z_.dat   del z_.dat
if exist z_.log   del z_.log

echo == Rebuild completed succefully
title Finished!
pause
goto :eof

:args
echo.
echo == Usage:   %%me%% OLD_REPO_PATH NEW_REPO_PATH
echo.
echo == Example: %%me%% file:///A:/SubVersion B:\New_repo
goto :eof

:err
pause